/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cpal.entrenamiento.common.logger;

import java.io.Serializable;
//import net.locaid.courier.common.StringUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author omar
 */
public class Log4jLogger implements Log, Serializable {

    /** The fully qualified name of the Log4JLog class. */
    private static final String FQCN = Log4jLogger.class.getName();
    /** Log to this logger */
    private transient Logger logger = null;
    /** Log name */
    private String name = null;

    public Log4jLogger() {
        this.name = FQCN;
        this.logger = getLogger();
    }

    public Log4jLogger(String name) {
        this.name = name;
        this.logger = getLogger();
    }

    /**
     * Return the native Log instance we are using.
     */
    public Logger getLogger() {
        if (logger == null) {
            logger = Logger.getLogger(name);
        }
        return (this.logger);
    }

    public void trace(Object... messages) {
        try {
            getLogger().log(FQCN, Level.TRACE, StringUtils.joinMessages(messages), null);
        } catch (Throwable ignore) {
        }
    }

    public void trace(Object message, Throwable t) {
        try {
            getLogger().log(FQCN, Level.TRACE, message, t);
        } catch (Throwable ignore) {
        }
    }

    public void debug(Object message) {
        try {
            if (getLogger().isDebugEnabled()) {
                getLogger().log(FQCN, Level.DEBUG, message, null);
            }
        } catch (Throwable ignore) {
        }
    }

    public void debug(Object serviceOperation, Object message) {
        try {
            if (getLogger().isDebugEnabled()) {
                getLogger().log(FQCN, Level.DEBUG, StringUtils.joinMessages(serviceOperation, message), null);
            }
        } catch (Throwable ignore) {
        }
    }

    public void debug(Object status, Object errorId, Object errorDesc, Object additionalInfo) {
        try {
            getLogger().log(FQCN, Level.DEBUG, StringUtils.joinMessages("status:", status, " |errorId:", errorId, " |additionalInfo:", additionalInfo), null);
        } catch (Throwable ignore) {
        }
    }

    public void debug(Object serviceOperation, Object requestId, Object status, Object errorId, Object errorDesc, Object additionalInfo) {
        try {
            getLogger().log(FQCN, Level.DEBUG, StringUtils.joinMessages(serviceOperation, " requestId:", requestId, " |status:", status, " |errorId:", errorId, " |errorDesc:", errorDesc, " |additionalInfo:", additionalInfo), null);
        } catch (Throwable ignore) {
        }
    }

    public void debug(Object serviceOperation, Object status, Object errorId, Object errorDesc, Object additionalInfo) {
        try {
            getLogger().log(FQCN, Level.DEBUG, StringUtils.joinMessages(serviceOperation, "| status:", status, "| errorId:", errorId, "| errorDesc:", errorDesc, "| additionalInfo:", additionalInfo), null);
        } catch (Throwable ignore) {
        }
    }

    public void debug(Object message, Throwable t) {
        try {
            if (getLogger().isDebugEnabled()) {
                getLogger().log(FQCN, Level.DEBUG, message, t);
            }
        } catch (Throwable ignore) {
        }

    }

    public void info(Object... messages) {
        try {
            if (getLogger().isInfoEnabled()) {
                getLogger().log(FQCN, Level.INFO, StringUtils.joinMessages(messages), null);
            }
        } catch (Throwable ignore) {
        }

    }

    public void info(Object message, Throwable t) {
        try {
            if (getLogger().isInfoEnabled()) {
                getLogger().log(FQCN, Level.INFO, message, t);
            }
        } catch (Throwable ignore) {
        }
    }

    public void warn(Object serviceOperation, Object message) {
        try {
            getLogger().log(FQCN, Level.WARN, StringUtils.joinMessages(serviceOperation, message), null);
        } catch (Throwable ignore) {
        }
    }

    public void warn(Object serviceOperation, Object errorId, Object additionalInfo) {
        try {
            getLogger().log(FQCN, Level.WARN, StringUtils.joinMessages(serviceOperation, " errorId:", errorId, " |additionalInfo:", additionalInfo), null);
        } catch (Throwable ignore) {
        }
    }

    public void warn(Object serviceOperation, Object status, Object errorId, Object errorDesc, Object additionalInfo) {
        try {
            getLogger().log(FQCN, Level.WARN, StringUtils.joinMessages(serviceOperation, " status:" + status, " |errorId:", errorId, " |errorDesc:", errorDesc, " |additionalInfo:", additionalInfo), null);
        } catch (Throwable ignore) {
        }
    }

    public void warn(Object serviceOperation, Object errorId, Object additionalInfo, Throwable t) {
        try {
            getLogger().log(FQCN, Level.WARN, StringUtils.joinMessages(serviceOperation, " errorId:", errorId, " |additionalInfo:", additionalInfo), t);
        } catch (Throwable ignore) {
        }
    }

    public void warn(Object message, Throwable t) {
        try {
            getLogger().log(FQCN, Level.WARN, message, t);
        } catch (Throwable ignore) {
        }
    }

    public void error(Object message, Throwable t) {
        try {
            getLogger().log(FQCN, Level.ERROR, message, t);
        } catch (Throwable ignore) {
        }
    }

    public void error(Object message, Object errorId, Object additionalInfo) {
        try {
            getLogger().log(FQCN, Level.ERROR, StringUtils.joinMessages(message, " errorId:", errorId, " |additionalInfo:", additionalInfo), null);
        } catch (Throwable ignore) {
        }
    }

    public void error(Object status, Object errorId, Object errorDesc, Object additionalInfo) {
        try {
            getLogger().log(FQCN, Level.ERROR, StringUtils.joinMessages("status:" + status, " |errorId:", errorId, " |errorDesc:", errorDesc, " |additionalInfo:", additionalInfo), null);
        } catch (Throwable ignore) {
        }
    }

    public void error(Object message, Object errorId, Object additionalInfo, Throwable t) {
        try {
            getLogger().log(FQCN, Level.ERROR, StringUtils.joinMessages(message, " errorId:", errorId, " |additionalInfo:", additionalInfo), t);
        } catch (Throwable ignore) {
        }
    }

    public void error(Object serviceOperation, Object status, Object errorId, Object additionalInfo, Throwable t) {
        try {
            getLogger().log(FQCN, Level.ERROR, StringUtils.joinMessages(serviceOperation, " status:" + status, " |errorId:", errorId, " |additionalInfo:", additionalInfo), t);
        } catch (Throwable ignore) {
        }
    }

    public void error(Object serviceOperation, Object status, Object errorId, Object errorDesc, Object additionalInfo, Throwable t) {
        try {
            getLogger().log(FQCN, Level.ERROR, StringUtils.joinMessages(serviceOperation, " status:" + status, " |errorId:", errorId, " |errorDesc:", errorDesc, " |additionalInfo:", additionalInfo), t);
        } catch (Throwable ignore) {
        }
    }

    public void fatal(Object... messages) {
        try {
            getLogger().log(FQCN, Level.FATAL, StringUtils.joinMessages(messages), null);
        } catch (Throwable ignore) {
        }
    }

    public void fatal(Object message, Throwable t) {
        try {
            getLogger().log(FQCN, Level.FATAL, message, t);
        } catch (Throwable ignore) {
        }
    }

    /**
     * Check whether the Log4j Log used is enabled for <code>DEBUG</code> priority.
     */
    public boolean isDebugEnabled() {
        return getLogger().isDebugEnabled();
    }

    /**
     * Check whether the Log4j Log used is enabled for <code>ERROR</code> priority.
     */
    public boolean isErrorEnabled() {
        return getLogger().isEnabledFor(Level.ERROR);
    }

    /**
     * Check whether the Log4j Log used is enabled for <code>FATAL</code> priority.
     */
    public boolean isFatalEnabled() {
        return getLogger().isEnabledFor(Level.FATAL);
    }

    /**
     * Check whether the Log4j Log used is enabled for <code>INFO</code> priority.
     */
    public boolean isInfoEnabled() {
        return getLogger().isInfoEnabled();
    }

    /**
     * Check whether the Log4j Log used is enabled for <code>TRACE</code> priority.
     * When using a log4j version that does not support the TRACE level, this call
     * will report whether <code>DEBUG</code> is enabled or not.
     */
    public boolean isTraceEnabled() {
        return getLogger().isEnabledFor(Level.TRACE);
    }

    /**
     * Check whether the Log4j Log used is enabled for <code>WARN</code> priority.
     */
    public boolean isWarnEnabled() {
        return getLogger().isEnabledFor(Level.WARN);
    }
}
